public class Test {
    public static void main(String[] args) {
        char[] ch = new char[]{'a','b','c'};
        String s1 = new String(ch);
        s1.intern();//把数组放入字符常量池
        String s2 = "abc";//从常量池中拿出
        System.out.println(s1==s2);
    }

    public static void main17(String[] args) {
        String s = "  Java  ";
        //去除两边空格
        System.out.println("["+s+"]");
        System.out.println("["+s.trim()+"]");

    }

    public static void main16(String[] args) {
        String s = "Java is the best language";
        //截取
        System.out.println(s.substring(5));
        //部分截取,左闭右开
        System.out.println(s.substring(5,7));
    }

    public static void main15(String[] args) {
        String s = "190.45.6577.89";
        //对于一些特殊的符号，必须使用\
        String[] str = s.split("\\.");
        for(String i: str){
            System.out.println(i);
        }
    }

    public static void main14(String[] args) {
        String s = "Java is the best language";
        //字符串拆分并用数组接收
        String[] str = s.split(" ");
        //for each遍历输出
        for(String i: str){
            System.out.println(i);
        }
        //拆分成多组，不均匀，遇到的一个拆分字符就拆，组数够就停
        String[] str2 = s.split(" ",3);
        for (String j:str2) {
            System.out.println(j);
        }
    }

    public static void main13(String[] args) {
        String s = "Java is the best language";
        //替换
        System.out.println(s.replaceAll(" ","_"));
        System.out.println(s.replaceFirst(" ","*"));
    }

    public static void main12(String[] args) {
        //格式化
        String s = String.format("%d-%d-%d",2025,3,25);
        System.out.println(s);
    }

    public static void main11(String[] args) {
        String s = "Java is the best language";
        //字符串转数组
        char[] ch = s.toCharArray();
        for(int i=0;i<ch.length;i++){
            System.out.print(ch[i]);
        }
        System.out.println();
        //数组转字符串
        String s2 = new String(ch);
        System.out.println(s2);
    }

    public static void main10(String[] args) {
        String s1 = "WLGD";
        String s2 = "wlgd";
        //大写转小写
        System.out.println(s1.toLowerCase());//wlgd
        //小写转大写
        System.out.println(s2.toUpperCase());//WLGD
    }

    public static void main9(String[] args) {
        //数值转字符串
        String s1 = String.valueOf(12);
        String s2 = String.valueOf(1.2);
        String s3 = String.valueOf('a');
        String s4 = String.valueOf(true);
        String s5 = String.valueOf(new Student("yeye",18));
        //字符串转数值
        //Integer Double是包装类型
        int data1 = Integer.parseInt("1234");
        double data2 = Double.parseDouble("12.34");
        System.out.println(data1);
        System.out.println(data2);
    }

    public static void main8(String[] args) {
        String s1 = "aaaaccccbbbb";
        System.out.println(s1.lastIndexOf('c'));//7
        System.out.println(s1.lastIndexOf('a',7));//3
        System.out.println(s1.lastIndexOf("cb"));//7
        System.out.println(s1.lastIndexOf("aa",8));//2
        System.out.println(s1.lastIndexOf('k'));//-1
    }

    public static void main7(String[] args) {
        String s1 = new String("aaaaaabbbbccccc");
        System.out.println(s1.indexOf("bb"));//6
        System.out.println(s1.indexOf("cc",4));//10

    }
    public static void main6(String[] args) {
        String s1 = new String("abcdefg");
        String s2 = new String("aaaaaabbbbb");
        System.out.println(s1.indexOf('a',3));//-1
        System.out.println(s2.indexOf('b',3));//6

    }
    public static void main5(String[] args) {
        String s1 = new String("abcd");
        String s2 = new String("abcdefg");
        System.out.println(s1.indexOf('b'));//1
        System.out.println(s1.indexOf('r'));//-1
    }


    public static void main4(String[] args) {
        String s1 = new String("abcd");
        System.out.println(s1.charAt(3));//d
        System.out.println(s1.charAt(-1));//IndexOutOfBoundsException异常
        System.out.println(s1.charAt(5));//IndexOutOfBoundsException异常

    }



    public static void main3(String[] args) {
        String s1 = new String("abc");
        String s2 = new String("Ab");
        String s3 = new String("aBc");
        String s4 = new String("ABCdef");
        System.out.println(s1.compareToIgnoreCase(s2));//1
        System.out.println(s1.compareToIgnoreCase(s3));//0
        System.out.println(s1.compareToIgnoreCase(s4));//-3
    }


    public static void main2(String[] args) {
        String s1 = new String("abc");
        String s2 = new String("ab");
        String s3 = new String("abc");
        String s4 = new String("abcdef");
        System.out.println(s1.compareTo(s2));//1
        System.out.println(s1.compareTo(s3));//0
        System.out.println(s1.compareTo(s4));//-3

    }



    public static void main1(String[] args) {
        int a = 10;
        int b = 20;
        int c = 10;
//        System.out.println(a==b);//false
//        System.out.println(a==c);//true

        String str1 = new String("hihi");
        String str2 = new String("hehe");
        String str3 = new String("hihi");
        String str4 = str1;
//        System.out.println(str1==str2);//false
//        System.out.println(str1==str3);//false
//        System.out.println(str1==str4);//true
        System.out.println(str1.equals(str2));//false
        System.out.println(str1.equals(str3));//true
    }

}
